﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.IO;

namespace Skecthial.UI.Services 
{
    /// <summary>
    /// Summary description for ControlLoader
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    [System.Web.Script.Services.ScriptService]
    public class ControlLoader : System.Web.Services.WebService
    {

        [WebMethod]
        public string LoadControl(string Data)
        {
            string Control = "";
            if(Data == "Profile")
            {
                Control = "UserProfile.ascx";
            }
            else if (Data == "DND")
            {
                Control = "DragAndDrop.ascx";
            }
            else if (Data == "Locations")
            {
                Control = "EventMap.ascx";
            }
            Page page = new Page();
            UserControl ctl = (UserControl)page.LoadControl("~/Controls/"+ Control);
            page.Controls.Add(ctl);
            StringWriter writer = new StringWriter();
            HttpContext.Current.Server.Execute(page, writer, false);
            return writer.ToString();
        }

        [WebMethod]
        public string LoadNewPost(string Data)
        {
            int dataLength = Data.Length;

            Page page = new Page();
            UserControl ctl = (UserControl)page.LoadControl("~/Controls/NewPost.ascx");
            page.Controls.Add(ctl);
            StringWriter writer = new StringWriter();

            HttpContext.Current.Server.Execute(page, writer, false);

            return writer.ToString();
        }

        [WebMethod]
        public string LoadPosts(string Data)
        {
            Page page = new Page();
            UserControl ctl = (UserControl)page.LoadControl("~/Controls/Posts.ascx");
            page.Controls.Add(ctl);
            StringWriter writer = new StringWriter();
            HttpContext.Current.Server.Execute(page, writer, false);
            return writer.ToString();
        }
        [WebMethod]
        public string LoadFriends(string Data)
        {
            int dataLength = Data.Length;

            Page page = new Page();
            UserControl ctl = (UserControl)page.LoadControl("~/Controls/Friends.ascx");
            page.Controls.Add(ctl);
            StringWriter writer = new StringWriter();

            HttpContext.Current.Server.Execute(page, writer, false);

            return writer.ToString();
        }

        [WebMethod]
        public string LoadDragAndDrop()
        {
            Page page = new Page();
            UserControl ctl = (UserControl)page.LoadControl("~/Controls/DragAndDrop.ascx");
            page.Controls.Add(ctl);
            StringWriter writer = new StringWriter();

            HttpContext.Current.Server.Execute(page, writer, false);

            return writer.ToString();
        }


        [WebMethod]
        public string LoadDetail(string _uid,string _fullname,string _type)
        {
            Page page = new Page();
            UserControl ctl = (UserControl)page.LoadControl("~/Controls/Detail.ascx");
            ctl.Attributes["uid"] = _uid;
            ctl.Attributes["fullname"] = _fullname;
            ctl.Attributes["type"] = _type;
            page.Controls.Add(ctl);
            StringWriter writer = new StringWriter();

            HttpContext.Current.Server.Execute(page, writer, false);

            return writer.ToString();
        }

        [WebMethod]
        public string AddNewPost(string _where, string _when, string _with,string _who, string _what)
        {
            Page page = new Page();
            UserControl ctl = (UserControl)page.LoadControl("~/Controls/NewPost.ascx");
            ctl.Attributes["_where"] = _where;
            ctl.Attributes["_when"] = _when;
            ctl.Attributes["_with"] = _with;
            ctl.Attributes["_who"] = _who;
            ctl.Attributes["_what"] = _what;
            page.Controls.Add(ctl);
            StringWriter writer = new StringWriter();

            HttpContext.Current.Server.Execute(page, writer, false);

            return writer.ToString();
        }

        [WebMethod]
        public void FBLogin(string Data)
        {

        }
    }
}
